﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace new_problem
{
    class GaussianBlur
    {
        public static Double[,] AddGaussBlur3(Double[,] surface)
        {
            Double[,] result = new Double[DataGen.N + 1, DataGen.N + 1];
            Double[,] middle = new double[DataGen.N + 3, DataGen.N + 3];

            for (int i = 1; i < DataGen.N + 2; i++)
                for (int j = 1; j < DataGen.N + 2; j++)
                    middle[i, j] = surface[i - 1, j - 1];

            // продляем границы
            for (int i = 1; i < DataGen.N + 2; i++)
            {
                middle[0, i] = middle[1, i];
                middle[DataGen.N + 2, i] = middle[DataGen.N + 1, i];
                middle[i, 0] = middle[i, 1];
                middle[i, DataGen.N + 2] = middle[i, DataGen.N + 1];
            }
            middle[0, 0] = middle[0, 1];
            middle[0, DataGen.N + 2] = middle[0, DataGen.N + 1];
            middle[DataGen.N + 2, 0] = middle[DataGen.N + 1, 0];
            middle[DataGen.N + 2, DataGen.N + 2] = middle[DataGen.N + 1, DataGen.N + 1];

            for (int i = 0; i < DataGen.N + 1; i++)
                for (int j = 0; j < DataGen.N + 1; j++)
                    result[i, j] = 0.08 * middle[i, j] + 0.12 * middle[i + 1, j] + 0.08 * middle[i + 2, j] +
                                   +0.12 * middle[i, j + 1] + 0.2 * middle[i + 1, j + 1] + 0.12 * middle[i + 2, j + 1] +
                                   +0.08 * middle[i, j + 2] + 0.12 * middle[i + 1, j + 2] + 0.08 * middle[i + 2, j + 2];

            return result;
        }

        public static Double[,] AddGaussBlur5(Double[,] surface)
        {
            Double[,] result = new Double[DataGen.N + 1, DataGen.N + 1];
            Double[,] middle = new double[DataGen.N + 5, DataGen.N + 5];

            for (int i = 2; i < DataGen.N + 3; i++)
                for (int j = 2; j < DataGen.N + 3; j++)
                    middle[i, j] = surface[i - 2, j - 2];

            // продляем границы
            for (int i = 2; i < DataGen.N + 3; i++)
            {
                middle[0, i] = middle[2, i];
                middle[1, i] = middle[2, i];
                middle[DataGen.N + 3, i] = middle[DataGen.N + 2, i];
                middle[DataGen.N + 4, i] = middle[DataGen.N + 2, i];
                middle[i, 0] = middle[i, 2];
                middle[i, 1] = middle[i, 2];
                middle[i, DataGen.N + 3] = middle[i, DataGen.N + 2];
                middle[i, DataGen.N + 4] = middle[i, DataGen.N + 2];
            }
            middle[0, 0] = middle[0, 2];
            middle[0, 1] = middle[0, 2];
            middle[1, 0] = middle[0, 2];
            middle[1, 1] = middle[0, 2];

            middle[0, DataGen.N + 3] = middle[0, DataGen.N + 2];
            middle[0, DataGen.N + 4] = middle[0, DataGen.N + 2];
            middle[1, DataGen.N + 3] = middle[0, DataGen.N + 2];
            middle[1, DataGen.N + 4] = middle[0, DataGen.N + 2];

            middle[DataGen.N + 3, 0] = middle[DataGen.N + 1, 0];
            middle[DataGen.N + 4, 0] = middle[DataGen.N + 1, 0];
            middle[DataGen.N + 3, 1] = middle[DataGen.N + 1, 0];
            middle[DataGen.N + 4, 1] = middle[DataGen.N + 1, 0];

            middle[DataGen.N + 3, DataGen.N + 3] = middle[DataGen.N + 1, DataGen.N + 1];
            middle[DataGen.N + 4, DataGen.N + 3] = middle[DataGen.N + 1, DataGen.N + 1];
            middle[DataGen.N + 3, DataGen.N + 4] = middle[DataGen.N + 1, DataGen.N + 1];
            middle[DataGen.N + 4, DataGen.N + 4] = middle[DataGen.N + 1, DataGen.N + 1];

            for (int i = 0; i < DataGen.N + 1; i++)
                for (int j = 0; j < DataGen.N + 1; j++)
                    result[i, j] = 0.000789 * middle[i, j] + 0.006581 * middle[i + 1, j] + 0.013347 * middle[i + 2, j] +
                                   0.006581 * middle[i + 3, j] + 0.000789 * middle[i + 4, j] +

                                   +0.006581 * middle[i, j + 1] + 0.054901 * middle[i + 1, j + 1] +
                                   0.111345 * middle[i + 2, j + 1] + 0.054901 * middle[i + 3, j + 1] + 0.006581 * middle[i + 4, j + 1] +

                                   +0.013347 * middle[i, j + 2] + 0.111345 * middle[i + 1, j + 2] +
                                   0.225821 * middle[i + 2, j + 2] + 0.111345 * middle[i + 3, j + 2] + 0.013347 * middle[i + 4, j + 2] +

                                   +0.006581 * middle[i, j + 3] + 0.054901 * middle[i + 1, j + 3] +
                                   0.111345 * middle[i + 2, j + 3] + 0.054901 * middle[i + 3, j + 3] + 0.006581 * middle[i + 4, j + 3] +

                                   +0.000789 * middle[i, j + 4] + 0.006581 * middle[i + 1, j + 4] +
                                   0.013347 * middle[i + 2, j + 4] + 0.006581 * middle[i + 3, j + 4] + 0.000789 * middle[i + 4, j + 4];

            return result;
        }
    }
}
